<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js">
		</script>
		<script>
			var selfurl = "https://localhost:44338";

			function GETRequest(url, api, success) {
				$.get(url + "/" + api, success);
			}

			function POSTRequest(url, api, data, callback) {
				$.ajax({
					type: 'POST',
					url: url + "/" + api,
					contentType: "application/json;charset=UTF-8",
					data: JSON.stringify(data),
					success: callback,
					dataType: "json"
				});
			}
			$(document).ready(function() {
				
				//get
				$("#feature").click(function() {
					GETRequest(selfurl, "SurveyFeatures",
						function(objs) {
							for (var i = 0; i < objs.length; i++)
								alert("功能名:" + objs[i]["name"] + "\n介绍:" + objs[i]["about"]);
						})
				});
				$("#order").click(function() {
					GETRequest(selfurl,"PutOrder?buyer=411481&address=6&park=8&seller=8",function(status)
					{
						alert("Status:"+status);
					});
				});
				//post
				$("#discount").click(function() {
					var data=[{id:1009}];
					POSTRequest(selfurl,"UseDiscount?order=1007&comfirm=0",data,function(obj){
						alert(obj["id"]+"\n地址信息:"+obj["address"]+"\n使用后价格:"+obj["price"]+"\n订单状态："+obj["status"]+"\n下单人:"+obj["belong"]+"\n下单时间："+obj["time"]);
					});
					
					
					});
					
				$("#post").click(function() {
					var data = {
						id: "111111",
						username: "admin0",
						password: "QQ12345678",
						location: 5,
						house: 1,
						num: 102,
						sign: "9OfubmVl+Yk121X9OWditSehVgRI"
					}
					POSTRequest(selfurl,"Register",data,function(objs) {
							alert(objs);
						});
				});
			});
		</script>
	</head>
	<body>

		<button id="feature">获取功能提示（不带参GET API）</button>
		<button id="order">提交订单（带参GET API）</button>
		<button id="post">注册用户(全POST)</button>
		<button id="discount">优惠券使用后预览结果（POST API 带参数）</button>
	</body>
</html>
